package com.yjhh.chdataservice.controller;

import com.yjhh.chdataservice.beans.DataCheckVo;
import com.yjhh.chdataservice.beans.DeptInfoVo;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.LogicService;
import com.yjhh.chdataservice.util.CommonResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by hlantian on 2017/9/26.
 */
@Api(tags = "数据统计以及排名等相关接口")
@RestController
@RequestMapping(value = "/service/ymbq")
@Log4j2
public class YMBQController {

    @Autowired
    private LogicService logicService;

    @ApiOperation(value = "获取家庭成员信息", notes = "根据家庭成员ID获取家庭成员信息")
    @ApiImplicitParam(name = "id", value = "家庭成员ID", required = true, paramType = "path", dataType = "String", defaultValue =
            "c77d30dd-f16e-42b3-a354-dc177b17561f")
    @RequestMapping(value = "/family/{id}", method = RequestMethod.GET)
    public CommonResultData<String> getById(@PathVariable String id) {
        //获取当前操作人信息
        String familyMember = logicService.findFamilyMemberById(id);
        return new CommonResultData<String>(HttpStatus.OK.value(), "suc", familyMember);
    }


    @ApiOperation(value = "获取搬迁对象已录入基本信息排名", notes = "根据行政区划编码获取搬迁对象已录入基本信息排名")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610900000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getMoveTopByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<DeptInfoVo>> getMoveTopByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<DeptInfoVo>> moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(),"no data");
        long usedTime = 0;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = logicService.getMoveTopByAreaCode(areaCode);
            usedTime = System.currentTimeMillis() - startTime;
        } catch (YJHHException e) {
            log.warn("getMoveTopByDeptNo",e);
        }
        moveTopByAreaCode.setRespTime(usedTime);
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "获取搬迁相关信息完整性排名", notes = "根据行政区划编码获取搬迁相关信息完整性排名")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610900000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getDataFillTopByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<DataCheckVo>> getDataFillTopByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<DataCheckVo>> fileTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(),"no data");
        long usedTime = 0;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            fileTopByAreaCode = logicService.getDataFillTopByAreaCode(areaCode);
            usedTime = System.currentTimeMillis() - startTime;
        } catch (YJHHException e) {
            log.warn("getDataFillTopByAreaCode",e);
        }
        fileTopByAreaCode.setRespTime(usedTime);
        return fileTopByAreaCode;
    }



}
